module Utils where

import List (find)
import Maybe (fromMaybe)
import Data.Graph.Inductive.Graph (lab, Graph)
				   
existsBy:: (Eq a) => (a -> Bool) -> [a] -> Bool
existsBy fun list = case find fun list of
					Just _ -> True
					Nothing -> False
				   
add_in_set_mode :: (Eq a) => [a] -> a -> [a]
add_in_set_mode list item 
	| item `elem` list = list
	| otherwise = item:list
	
get_label :: (Graph gr) => gr a b -> Int -> a
get_label gr = fromMaybe (error "No label") . lab gr
	
first_of_three (x,y,z) = x
second_of_three (x,y,z) = y
third_of_three (x,y,z) = z